package com.hbnu.controller;


import com.hbnu.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;

import java.util.Map;

@Controller
public class HelloController {
    @GetMapping("/hello")
    public String hello(){
        return "/index.jsp";
    }

    @RequestMapping("/demo1")
    @ResponseBody
    public void demo_1(String name,String address){
        System.out.println(name + "-----" + address);
    }

    @RequestMapping("/demo2")
    @ResponseBody
    public void dmo_2(User user){
        System.out.println(user);
    }

    @RequestMapping("/demo3/{name}/{address}")
    @ResponseBody
    public void demo_3(@PathVariable("name") String username,@PathVariable String address){
        System.out.println(username + " -------- " + address);
    }

    @RequestMapping("/demo4")
    @ResponseBody
    public void demo_4(WebRequest webRequest){
        System.out.println(webRequest.getContextPath());
        Map<String,String[]> maps = webRequest.getParameterMap();
        for(String s:maps.keySet()){
            System.out.print(s + "-----> ");

            System.out.print(s + " -----> ");

            for(String ss:maps.get(s)){
                System.out.print(ss + " ");
            }
            System.out.println();
        }
    }
    @RequestMapping("/demo5")
    @ResponseBody
    public void demo_5(){

    }

//    public String redirect(Model model){
////        model.addAllAttribute("username","赵六");
//    }

}
